package api

import (
	"gitee.com/linxing_3/sr-core/domain/api"
	"gitee.com/mkwchecking/sr-admin/apps/holoHistMsg/acl"
	"gitee.com/mkwchecking/sr-admin/apps/holoHistMsg/service"
	"github.com/gin-gonic/gin"
)

func NewHistoryMsg(msgSrv *service.HistoryMsg) *HistoryMsg {
	return &HistoryMsg{
		msgSrv: msgSrv,
	}
}

type HistoryMsg struct {
	msgSrv *service.HistoryMsg
}

// FetchHistoryList
//
//	@Summary	获取历史消息列表
//	@Tags		历史消息
//	@Accept		json
//	@Produce	json
//	@Param		rid		query		string	true	"房间ID"
//	@Param		kw		query		string	false	"关键词"
//	@Param		pageNum	query		int		false	"页码"
//	@Param		pageSize	query		int		false	"每页数量"
//	@Success	200		{object}	[]acl.MessageItem
//	@Router		/historyMsg/list [get]
func (s *HistoryMsg) FetchHistoryList(c *gin.Context) {
	req := new(acl.HistoryMessageFetchReq)
	apiCtx := api.
		NewCtx(c).
		WithReq(req)

	if !apiCtx.Do() {
		return
	}

	res, total, err := s.msgSrv.GetRoomHistoryMsg(apiCtx.Context(), req)
	if err != nil {
		apiCtx.WriteErr(nil, err, "获取历史消息列表失败")
		return
	}

	apiCtx.WritePageOK(res, total, req.PageNum, req.PageSize, "ok")
}
